fixed handling of end of file
added exceptions for comments
cleaned up some formatting