Fix some potential bugs