Fix issue #46 (divide by 0), merge jonnybazookatone code (issue #45)