Clean up code and add some comments for tagging