speed improvements and wider search (not entirely tested!)