move globals out of document.ready
fix the weird issue I was experiencing