Changed logic version 1