Fix some code bugs