reorder code pieces
add tests to test FLAG_SPVARS and @key