Self-updating feature, indentation fix, and SQL cleanup

Please don't close any issues apart from #87 based on this PR, there are more to PRs to come.
In fact, I think #87 should be closed.

Basically, this does more work on the self-updating feature, and starts work on #93 

Also, 58b7ac0 is misnamed and should be named "Some SQL cleanup"