Fix return type declaration of table_get_header
Fix some spaces
Use functions for decoding/encoding
Use more compact combined declaration+assignment
Declare some internal variables as C-types

No need to cast them to python objects in between calculations.