Adding logging facility + fixing bug