Cleaned up unused code, added some comments