move code away from io event