completed inverse bwt with helper functions