fixed a couple of bugs, now result should be correct