Implement gen for Write/Writeln...added more features in factor()