Fixed bug which migh have caused crashes

Can't test it, please tell me if that worked, thanks!