Replaced FLAG variables with the more simple int. Converted to ANSI C.