Cleaned up code a bit (removed print statements), added comments.