improved map rendering code