Add SHA-512 support (hacked) and a bit of cleanup