cleanup code, add offset

Cleaned up serialization code, added serialization of offset