more or less finished, just need to tweak some stuff. merging branch.