Reorganized code for ease of use and consistency.