cleaned up commented code, added a quit function to end gracefully