Factored some more code
Factored some more code