improved partially generalized function and removed IO