Refactored quantities and units

* Created QuantityFactory
* Removed some code duplication
* Fixed some warnings