Rewrite to use a controller pattern