New functions and cleaned up some other things.