fixed the deletion bug my last fix caused, and added a tiny amount of numerical stability