Refactor code based on review