update sidebar code to use where statement