almost fully workable, need test

Signed-off-by: apporc <appleorchard2000@gmail.com>