Trim polyfill, code cleanup