refactured pieces, need to fix test code