fully incoporated with fredo's changes and db