added check for length before getting a slice
changed to new debug2 macro