refactor output to render array, and make unit test