Do some code refactoring