Rearranged all functions

Rearranged all functions, functions can be called from outside now