refactor: generate components output in a function