Refactored most of coe to make it module. Seems to work on 'good' data