Added some inline comments and cleaned up code some.