Final Version. Cleaned up code.