merging with ahfaj's codes