code refactored