Replace deepclone with a hardcoded cloning mechanism. Fix #4