refactored to prevent potential problems