Added distribution specs and refactored distribution code.