add encode function and moving data for convenient in the future