added checking equality and fixed some bugs