add some defend code

add some defend code to spaces, correct some bug.
never optimization too early.