Refactor all the code