refactoring complete and works on localhost