Refactoring + bug fixed