Rorganize parser and improve error handling