optimizations

i changed the functions to macros (i tested it and the improvement is
big)
i also released memory we forgot to handle.

the use of the macros is exactly the same as using a function except you
cant use a variable named Macro_tmp as a parameter to the macro