Cleaned up the code quite a bit, removed commented out debug statements and methods that are no longer used. Also added some attribution.