Refactor code to pass metric