Refactoting code