fix quit bug, clean the code and update for integration