changing around code slightly; next steps require testing and playing around with signal handlers