this if branching is a little awkward to read