Working and tested implementation