datastore: manually refactor few corner cases

Signed-off-by: Luka Perkov <luka.perkov@sartura.hr>