Adds missing variable declarations and removes dead code.