optimized some bug fixes