refactored almost all of files