Fixed some issue where draining can sometimes cause nullpointers.