Only set custom class when valid class
Specify returning of generated keys before using them

This is a herp derp fix