Fixed and documented some bugs noticed by clang