move write functionality to map phase