fixed a bug and refactoring shiiet