Minimally tested but seems to work