First commit, transplanting code from private project.