Algorithm v3

edited the main code some