Fixed an issue that caued code to execute in the wrong order leading to a possible softlock