increased speed by some percents by converting small functions into macros.