dedup code for clarity at the cost of speed