Added a bit more verification and some more useful error messages