Remove unused function

also adds small optimization