fix prime check algorithm