Restructured code; added lots of stuff

... that was apparently missing.
Also fixed error transmission.
To do: Take care of actual error display.