Found this and had to adapt it