refactor and add mapping function