Changed variable filenamenotgiven to filenamegiven
and changed all assignments to it from FALSE to TRUE
and vice-versa to make the logic correct