refactored to reduce clutter