refactored code with self