Fix main bugs.