Refactor code, add mpre tests.