Removed unused variables and code improvements