Refactoring and improving readability