Optimized the input loop