Function and variable scaling added; not yet tested