refactored for memory mapped IO