Be a bit more defensive in some hacky code