build the functions, needs testing