Copied from a smilar project on github and made to compile with 2.2