Fixed serveal bugs.