runs much faster after commenting out switch statements