refactor to remove repetitive if-condition