Extracted some logic into module (will reorganize it later on)