Cleanup code, simplify, revise controller format, add controller for image template