Improved validation and removed unused code.