working, need to add some tests, though