a better map + minor refactor