Move residuetype handling to its own file.

Change-Id: I430dcb08db65479d4865e032a24effbacc87d28e