Add loading state function