Refactor with globals