Refactor using library code