Move logic out of the parser