Porting code from mapstore repository