optimized and fixed bugs