simplifying code for checking conditional code for key