Fixed problems, made it compile, renamed things. Have a close look at all the changes in this commit please.