added output and fixed naive