more optimizations
moved function