fixed inplace implementation