several fixes and improvements
also adding some new test case