Incomplete, but compiles and runs for basic case. Untested