improved function openfiles -- introduced callback function, useful when using openfiles from other modules