Clean up code and add comment