Major refactoring. Basic dependency system (currently broken)