change this logic it is not a good practice define a method inside another