cleaning things up a bit and separating logic out of the template