Reworked the bugfix implemented by goatpig