Several fixes and mprovements