Cleaned up code to remove unused and confusing portions.