Fixed error handling for empty input string