code cleanups, started optimized funcs