refactored added writelines.appendto