improvements by Dmitry