ubercode cloned from http://psha.org.ru/cgit/psha/ring