Code cleanup and add some inline documentation