basic functionality now working, in need of some refactoring