Merge with galaktor's version