improving speed and taking out legacy code