update for performance
fix a bug: null will not be encoded properly
make it more beautiful