Some ninor code refactoring