added some comments, changed some code. super mess!