add function quit. Too many bugs and incompleteness.