fixed bug with bad logic