Implements #533, #645, #659 and #676