Add exception for error messages, move code