db routines refactored

- refactored basic algorithms for provider
- added smart Record type to obtain diff's