Fixing bugs and adding remaining functionality