\spacefactor complaints

The errors

! You can't use `\spacefactor' in vertical mode.
\@->\spacefactor 
                 \@m 
or
! Improper \spacefactor.
...
come of using a LaTeX internal command without taking the precaution of fooling LaTeX that you're inside it. The problem is discussed in detail in "@ in macro names", together with solutions.