Added logging; reworked to conform to google's python style guide