Fixed bugs related to incorrect map and write new instance

Signed-off-by: Herbert <herberthb12@gmail.com>