Refactored for cleaner code