Added some logging and minor refactorings