Added globals, moved functions to dedicated file