split into MVC somewhat (not quite working yet)