fixed some arithmetic in stg code