fixed yet another bug, might refactor that function later