Some protections and bugfixes to stop server crashing