Merged Owen's code.