optimize some stuff into macros to avoid func. calls