More cleanup & less globals