better signal handling and reporting, minor optimizations and refactoring