Adding the missing files and fixed a few bugs.