refactor code to meet new requirements