Fixes #56, fixes #52, fixes #4 and a whole lot more.