Added error message when code is invalid