updated bugs and made some optimizations