more code cleanup, new function to handle user_state changes