Implement constructor registration and toObject