refactoring
continued refactoring for readability
better exiting
handle nested expressions
minor cleanups for style