move mmap wrangling to functions