started optimizing in functions.h