refactored and used callback