Updated test + code to handle 404 and 401, not optimal yet though