map object extracted, some tidying done
remove duplications and make functions more expressive