added lots of log statements and comments