Add some helper functions

Makes the code somewhat smaller - may need another pass
Fix 64 bit key too