Tidied up the error reporting.
Changed the structure of the source