Code now runs without errors. Needs testing