Changed the api a bit, and fixed some issues with serialization