Better error reporting facilities and input sanitycheck moved to own file for clarity