cleanup and make interrupt code more robust