Brought code over from other repository.

All test cases pass. Everything should be good to go!