Various small fixes and adjustments
Added tests