Fix bugs due to mismatched data type