this program works, but its too slow