Fixed Bugs and Added Testing Code