added exception handling to threads