Add unit tests; improve parsing