Refactors code to improve performance