revert changes to init and free memory properly