add --sgof flag and code refactor