Removed unused BadGateway function and fixed unit tests