I think this might help make it work without freezing at the end. Or it will cause terrible terrible things to happen. Probably the first one though