Add unit tests for sha512
Fix refactoring crash bugs