minor changes to clean up code and add proper comments