some refactoring and clean up. will add packages next.