many improvements

read the code to learn more