the whole code refactoring and minimization