make this look like the latest C version
more efficiency