null reference exception in very specific case