Finished implementation

TODO: clean up code and intialization