Fix main bugs