Fixed bug with tenant ID conversion and some cleanup