Improved input handling