implementing the logic