code refactoring and utilities