Revert "Revert "Code refactor. Corrected variable declarations.""

This reverts commit d43fd23685d3e328e911e324f620836b9ead7ad4.