refractor code.
fix bug on serialization