Inverse updated - this code is not mine. This is hard as hell.