switched to logging lib, simplified code