Add error checking to flag parsing