fixed toObject method