Improved input parsing