Copied over the remaining code.