modified it a bit to allow output to handle multiple classes