Address some bug. Start to handle things in unit testing.