fixed bugged code