Noted inspiration from internet solution for this problem