Added some bits from else-where