Copied in most of the functionality and a test page