Many fixes
Added test