Wrong variable used. It's funny how some bugs take a long time