refactored to decrease method complexity