moving function definition so it gets declared only once