refactor report function