Testing and Corrections

Added code to test the functions. Corrected a few errors.