Cleaned up and added many comments