Merged with stas's work