implemented initial pluggable behaviour and more refactoring/decoupling