Improved parsing code