major fixes, final version