refactored rendering into functions and made clever use of transducers