Main reworked for flexible usage