Refactor controller logic out of windows