improved input handling