Use < instead of != for some loop checks