Extracted common code from BTree and Flat array and other cleanups

Change-Id: Ib255f69f75367abb49aa21077d0949e911eba442
Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>