migrate large of code from qnnshop;