Cleaned up code and added function comments