Fix comparison with nil bug that can happen at end of file