fixed the bugged code