Fix bug in app restarting