decoupled algo from ORM and changed added tests