working version with crappy test that needs to be refactored