Code: General fixes and improvements