corrected to use writeline() instead of raw()