Numpy 1.8 support, some cleanup and a bug fix.