Finished fit and keep ratio function and fixed some warnings.