major fixes, serialization support and memory leak fixed