Optimized and fixed bugs