added most of ugo's changes