Some code re-factoring