optimized Input and cleaned up