Improved dependecy management, clean some moved code