Refactor and update dependencies