Clean up unused / duplicate imports, etc.

- Removed unused / duplicate imports and variables.
- Renamed parameter name 'type', which is a reserved built-in name,
  to appropriate names.