imported more of Justin's changes