first implementation of APPLY