Made a few modifications to increase reliability