rewrote how the functional version works, with demo page