Factored and eliminated some dead code