fixed warnings and added Error Message handling