objectified the implementation
TODO: test and generalize functionality