move logic out of views to stop setting locals