cleaning up code; adding global vars