moved reader loop to main class to allow running as a service