refactor, reduce code

I trimmed some unused code out and added some inline comments where it looks to the existing code would not work - don't know how to test this though. Haven't given this much time, feel free to just close this ticket if what I have written is nonsense.