Added some more logging
Cleaned up some code