this is an unstable version (narroe bound reinitialization does not work error is in mini and maxi func.)but I made it to continue it later on