Refactored serialization logic. Normalized white spaces.