Fix bug where constants were not checked for division by zero and related problems