refactoring, update dao tests, extracted sql