new function and minor changes