replace this with if(isliving(loc))

same with all other checks like this

Check out mob_helpers.dm