better output and fixed empty initial file case