fixed the algorithm
deleted unused methods and class