Some code re-structuring