first implementation of the logic