refactor to use return instead of global var

Signed-off-by: Gowrishankar Rajaiyan <gsr@redhat.com>