added logger and debug flag, some cleanup