fixed bugs & optimized