Extracted method to parse output and return result