working code with tests, stashing this one to do full testing