refactoring code into own functions
wrote override onData function