fixed a bug in checkForError
some cleanup
tweaks