de-globalized some vars, fixed logging