Used pimpletrest code as a starting point