Moved print statement to avoid referencing before assignment