move protocol check to the top