Refactoring

Hi, I wanted to add a feature to your package (which is really great !), but first it looked like it needed some refactoring (extract method, separate classes to the own files, etc.)

Here's what I've done. It may not be perfect, but the work is started :)