main function generalized