Refactor report code