Remove unused code and cleanup error message