Added memories and refactored bit manipulation.