work but is refactored and has the nth problem function