Major reorganisation, rewritting, and tests

Programs have been moved to bin, tests have been created and modules
have been reorganised and reduced. More tidy.