Fixed bug, added more error-checking.
Added scale factor support. Untested, WIP, YMMV.
Resolved conflicts.