Implemented solution based on agjacome