Why did you typedef that struct as a pointer? I really don't recommend hiding a pointer inside a typedef.

Why all the horrible global variables?