Add check for duplicate questions

Also improved readability of a part of code