complete code refactor