refactors by remove unused code and reogrinaize code.