restructure conditional code