Cleaned up variable and function declarations.

This should help prevent scope craziness.