This code were in ready handler because we could not require "protocol" before ready before. It is now safe to move the code out.