added check for empty range