refactored logic for work with content provider