Added tests, fixed some bugs

loadAlgo now takes a mode parameter

writeDB had an error where the headers['encrypt'] wouldn't be recognised
as true.