Improvements for Java and C# class modes

Fixes #416

/cc @isagalaev