many fixes from jreybert