Code cleanup.
Supporting device assignment and some code cleanup.