refactor memories and addresses