Fixed NPE
Added some basic debug logging