minor rewrite, cleaner code
added generation of __pack() functions