bugs fixes, added unitests, better code...