Update Apply function (not finished yet)