split up apply function