apply() implementation