Backporting stuff from lqez & akitchen