Various bugfixed & optimizations