Improved testing part and fixed some bugs in the business logic.

Signed-off-by: Paolo Maresca <plo.maresca@gmail.com>