cleaned up apply function