baically finished implementation

TODO: refactoring, to clean up the code