Fixed parsing. May not be as pretty as I'd like, but it works