Remove whitespace, clean up code and fix bug.