Fixed some ugly bugs.