added check for length == 1 to prevent JSON parsing errors during empty respones