demo cleanup
reference cleanup
clean up template
improve prediction loop