fixed many bugs and made stable