Moving some methods to lib and testing
Removed functions moved to lib
Moved more functionality to the lib for better testing