refactor output and rendering functions