Merged Mills's code into Matthew's