functions improved and tested
moving and repurposing functions