refactor for more flatness, added quit()