added comments, cleaned up some formatting