New functions and reduced code a little.