Refactoring some poorly written code which improved performance by approx 60