refactored logging functions.. added a bit more logging