First working version, results not validated with manual testing yet