add unit test, abstract compare function out of db