Fix implementation and tests for map