Fix bug in mapper function