Fixed all the issues.item2 needs to be added when it is not -1. Because
it may be because item2 is popped and hence stack becomes empty.