 
 writeNdjson = (file) ->
 	return (schedules) ->
-		#return console.log schedules   # todo: remove
 		task = Q.defer()
 
 		stringify = ndjson.stringify()
-		file.on 'error', (err) ->
+		stringify.on 'error', (err) ->
 			console.error err.stack   # todo: remove?
 			task.reject err
 
-		file = stringify
-		.pipe fs.createWriteStream path.join __dirname, '../data', file
+		writeStream = fs.createWriteStream path.join __dirname, '../data', file
 
-		file.on 'error', (err) ->
+		writeStream.on 'error', (err) ->
 			console.error err.stack   # todo: remove?
 			task.reject err
-		file.on 'finish', (end) -> task.resolve()
+		writeStream.on 'finish', task.resolve
 
+		stringify.pipe writeStream
 		for id, schedule of schedules
-			return console.log schedule   # todo: remove
+			delete schedule.start
+			delete schedule.days
 			stringify.write schedule
+		stringify.end()
 
 		return task.promise
 

simplify = Q.defer()
schedules = {}

# read & accumulate data
readCsv 'calendar.csv', processSchedule schedules
.then () ->

			{ available: [], notAvailable: [] }   # saturday
		]
		for date in schedule.available
			days[moment(date).day()].available.push date
		for date in schedule.notAvailable
			days[moment(date).day()].notAvailable.push date

		for day, name in days
			if day.available.length > day.notAvailable.length
				schedule[daysOfWeek[name]] =
					default:	true
					exceptions:	day.notAvailable
			else
				schedule[daysOfWeek[name]] =
					default:	false
					exceptions:	day.available

		delete schedule.available
		delete schedule.notAvailable
