refactored logic of DB storing