refactored challenge response into separate functions