Add some checks to prevent server crashing