You could have put these checks in _map_cache (then you don't have to repeat the code).