Cleaning up code and commenting