Fixed the way data is marshaled

Finally gotten around to doing this. This should result in:
- Better performance
- Lower RAM usage

Let's hope I didn't miss anything.