max profit func added