Fixes parser bugs and adds tests