removed duplication in class algorithm