Feature/refactoring

This superseeds #12 

@japaveh Thanks for the initial work. I have some spare time now and will continue some parts :)