major fixes - needs testing