Various bugfixed and improvements