working version (kind of) - cleaned up