More unit tests and small code fixes

Signed-off-by: Daniele Ricci <daniele.athome@gmail.com>