refactored toJSON()