Refactor controller and build window