Finished initial implementation. Untested...