finished phase 2. Fixed bug on file writer.