Various patches and improvements

Is there an issue of overflowing here?