LOTS of refactoring
 - extracted functions

Signed-off-by: Felix <felix.herz@hotmail.de>