cleaned up wrapping algo, still lose ends