started working through @jrrideout's comments