Add unit tests, compartmentalize coe