merged changes & optimizations