Improved logic for handling requests