improve integral function