refactored to reduce overhead