Replace if condition with a better code

Signed-off-by: Umair Khan <omerjerk@gmail.com>