add encode! and cross! function and test encode!