Refactored to reduce SQL overload