Parse codes. Fix bugs. Add tests