Structure as a plugin

Major changes, create a plugin structure.
Add recursive function to check conditions and replace them by joins
reference.