Optimized the parsing logic to duplicating the code