moved functions in global scope to end off file