Moving log handling to if/main block