With Andrew's input, this has been cleaned up.