fixing one last bug, and solving the actual code