Cleaned up unused code.
Added more documentation.