Added Error messages, before the error is thrown

fixed some errors