cleans up the code and adds additional comments