tried to refactor the code to reuse code (does not compile)