[refactor] Attempting to improve logic of the code to bring it together.