extract most logic to separate module