refactored and added hooks