rearrange code in fcgi for simplicity