Shouldn't this be structured as if/else? Also, you can factor out the common code at the top.