Cleaned up, added some comments.