Improve variable organization and coding style