Functions added. Beginning some refactoring.