Refactor usage of global vbles