removed references to Number due to compiler bug, changed functions slightly