add extend, move fns outside of fn