add buffer max size and a lot of corrections
fixed arguments control