bug fixing refs #1576 + small code improvements