Fix for null reference bug