Removed global variables and tried to improve performance across Chrome and Firefox