better template for toObject() and fixed example in readme