lots of optimize funtions implemented