integrated latest changes and additions from alex von rhein's branch