fixed broken logic