reworking code for a better simple, cleaner and more extensible design