cleaned up code and added more description