move problem1 functionality to separated function