Serilization, reusing some code from another project with some tweaks