a little design and some refactoring