cleaned up some code, added signal handlers to exit gracefully
Merge remote-tracking branch 'upstream/master'