Cleaned up and added more comments