Changed bit to fenwick to avoid clashes.
Added error checking to fenwick tree.
Added more granular memory error checking.