Refactoring code further