Organizing code into packages

Re-factoring code based on discussion with Daniel