Fix menu and termination bugs, adds tests