Moved variable declarations to the top of functions for consistency.