working version before moving functions into a class