add functions plus improved version