Added the possibility to change the output function.