rewrite map function