working prototype. need refactoring