redo a lot of code :)

Signed-off-by: Simon Peeters <peeters.simon@gmail.com>