Hand-made merge of Linok's and Loyan's commits