added Bonnie code and tweaked