Some code refactoring / cleanup