consolidated all parsing logic