refactored initializing process and moved scripts and functions to lib directory