Refactoring

bugs are fixed