Updated the comments and cleand up the code