big refactoring thanks to @flyingmachine :sunglasses: