Code cleaned up and comments added.