Updated code with comments and small changes. Renamed to proper format.