Dan's code

Updated by him. Now compiles.