Code for my icfp contest 2014 entry