Fixing minor bug in logic