some improvements and additions by byterider...