fixing encoding of db calls, adding protection for empty responses from db