Some code clean-up

Got rid of some code duplication