fixed lineending bug
cleanup
fixed file writing mechanism