Refactored and updated a lot of code