refactored to prepare for different handlers