clean up code, add comments