Simplified code according to Mats suggestions
Started refactoring code into the extension class
Simplified main method