integrated writer into Makevars, cleaned up some mess
fixed compiler warnings and pointer errors