fixed some refactoring alga