Added missing files
A few potential bugs removed