Refactored for greater efficiency