refactor a little

1. de/serialize refactored  to methods.
2. Output file now overwrites instead of append