Riis's initial code. Kept for reference