Fix #98 and refactoring

Signed-off-by: Clement Escoffier <clement.escoffier@gmail.com>