Working version of fdb code