refactored common stuff to globals