Added reset function and refactored sending error messages