rewrote where as functions