Made switch handling more efficient