Cleaned up and added comments.