The kidneys produce urine through ultrafiltration and selective reabsorption. During ultrafiltration in the glomerulus, water and small molecules are filtered from the blood into the renal capsule. Then in the nephron tubules, useful materials like water, salts, glucose and amino acids are reabsorbed back into the blood while waste products remain and pass into the urine. The composition of urine is affected by diet and conditions like diabetes, as well as environmental factors such as temperature.