improve performance, fix empty map bug