Fixed naive code