some optimisation, gonna finish it later

*to do: put new function in the global