Fixed stupid bug.
Debug code. But it seems to work now.