How to redirect anonymous user to 404 instead of 403?
I have had some odd experiences with user_is_anonymous(). Try using negation with user_is_logged_in(). For example:

if (!user_is_logged_in()) {
    // Do stuff
}