Cleaned up some code format and added comments.