massive refactor and seperation