Added a couple log statements and a little logic