incorporate rdebath's changes