some very complex stuff passing tests now