Code amended for most of the functions.