Miscellaneous tweaks and optimizations to p_map.c