split logic to better organize the code