fixes #2411 Refactor /lib to app/models/concerns or app/controllers/concerns and app/services,
plus other code cleanups