Refactor the code architecutre