moved some lines around, not sure if it solved the bug