removed unused code and better error message