Some code refactored