complete rewrite of system for more readability and easiness of development