Refactor the whole system