clean up the code a bit
couple small crash fixes.
some quick bug fixes