updates plus a second version based on Brooks' reddit code