Jeff bug fix

Finished my bug fixing, merging my code into the master.