Implemented #20 #21 #22 and initial versions of #17 and #18