Gadget fix

Hi, 

There were some overflows in get_block_types() in gadget.py. I have fixed them and also rewrote the whole function

It seems to work for me.

Cheers,
   Sergey