fixed apply function