Some refactoring

Move functions to diffent files
Change some function