Adding variable declarations and code cleanups