moved some functions a scope up