Refactor from the beginning