Optimise get_next_line and fix bug with folder