Code cleanup and added a logger