Linx to do cleanup

Did some code clean-up and took care of TODOs. Most of this is untested so far, I'll be working on that this week. Will submit another pull request with bug-fixes if I find them.