Code refactor into something like MVC, also add some templates