refactored the code, now it is much more modular and extandable.