refactored for cleaner code