Finished initial version, needs commenting