Cleaned up, added comments, etc