removed global state and returns instead of printing