full code refactor