changed apply function, in order to compile with older g++ versions