Tidying up the parsing code a bit