fixes #2411 Refactor /lib directory and STI /models

as well as app/models/concerns or app/controllers/concerns and app/services, plus other code cleanups