Fix some errors, checked with compiler