Fixed main bugs