rebased on beangle 19