Made functions smaller, clearer, and better named.