Fix issues #4 & #6 & #7 & #8

Some code changes, possibly not entirely correct, to fix #4 and another issue while parsing a simple file.