Fixed bad references. Move some variables to globals from map.