Some of the functions appear to not work out of the box. In general, this code needs a review, and added comments.