Fixed inheritance and fixed recursive toJSON