fixed ugly bug regarding KeyError "class" not in class item :)
thank you StackOverflow, again!
some cleanup