improve script margin and pnl_funcs.sql