Cleaned up, added comments.